package com.yonyou.iuap.ipaas.connector.sdwcoatencent;

import cn.hutool.json.JSONUtil;
import com.yonyou.iuap.ipaas.connector.sdk.api.model.ConnectorParams;
import com.yonyou.iuap.ipaas.connector.sdk.api.model.ResponseAttributes;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.request.base.MaterialSaveRequest;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.request.base.SkuQueryQueryRequest;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.request.base.WarehouseQueryRequest;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.api.model.request.common.CommonQueryRequest;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.internal.LxwcoatencentConnection;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.internal.SdwcoatencentConnection;
import com.yonyou.iuap.ipaas.connector.sdwcoatencent.internal.operation.BaseOperations;
import com.yonyou.yonlinker.ysb.runtime.extension.api.runtime.operation.Result;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;

public class LxBaseOperationTestCase {
    private static Logger logger = LoggerFactory.getLogger(SdwcoatencentOperationsTestCase.class);

    private LxwcoatencentConnection connection;
    public static final String host = "https://openapi.lingxing.com";
    public static final String appkey = "ak_PHLHgN6qXgUdh";
    public static final String appSecret = "Q9WyQm4H2DF8qfAGP9V4BA==";
    public static final String outerHost = "127.0.0.1:8080";
    public static final String httpTimeOut = "300000";
    private BaseOperations baseOperations;


    @Before
    public void before() {
        this.connection = new LxwcoatencentConnection(appkey,appSecret,host,outerHost);
        connection.validate();
        this.baseOperations=new BaseOperations();
    }

    @Test
    public void batchSaveUser() {
        CommonQueryRequest commonQueryRequest = new CommonQueryRequest();
        commonQueryRequest.setOffset(0l);
        commonQueryRequest.setOffset(10L);
        Result<String, ResponseAttributes> res = baseOperations.querySupplierList(connection, commonQueryRequest);
        System.out.println(JSONUtil.toJsonStr(res));
    }@Test
    public void getWarehouseList() {
        WarehouseQueryRequest commonQueryRequest = new WarehouseQueryRequest();
        commonQueryRequest.setOffset(0l);
        commonQueryRequest.setLength(10L);
        Result<String, ResponseAttributes> res = baseOperations.queryWarehouseList(connection, commonQueryRequest);
        System.out.println(JSONUtil.toJsonStr(res));
    }@Test
    public void getProductSkuList() {
        SkuQueryQueryRequest commonQueryRequest = new SkuQueryQueryRequest();
        commonQueryRequest.setOffset(0l);
        commonQueryRequest.setLength(10L);
        Result<String, ResponseAttributes> res = baseOperations.queryProductSkuList(connection, commonQueryRequest);
        System.out.println(JSONUtil.toJsonStr(res));
    }
    @Test
    public void getShopList() {
        Result<String, ResponseAttributes> res = baseOperations.queryShopList(connection);
        System.out.println(JSONUtil.toJsonStr(res));
    }
    @Test
    public void syncMaterial() {
        MaterialSaveRequest materialSaveRequest = new MaterialSaveRequest();
        materialSaveRequest.setCode("test111");
        materialSaveRequest.setInTaxrate("1");
        materialSaveRequest.setInTaxrate_Name(1f);
        ArrayList<MaterialSaveRequest> materialSaveRequests = new ArrayList<>();
        materialSaveRequests.add(materialSaveRequest);
        Result<String, ResponseAttributes> res = baseOperations.syncMaterial(connection,materialSaveRequests);
        System.out.println(JSONUtil.toJsonStr(res));
    }
}
